package com.lagou.numbersort.step3;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class NumSortDriver3 {
    public static void main(String[] args) throws IOException, URISyntaxException, ClassNotFoundException, InterruptedException {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf, "NumSortDriver");

        job.setJarByClass(NumSortDriver3.class);

        job.setMapperClass(NumSortMapper3.class);
        job.setReducerClass(NumSortReducer3.class);
        job.setMapOutputKeyClass(LongWritable.class);
        job.setMapOutputValueClass(Text.class);
        job.setOutputKeyClass(LongWritable.class);
        job.setOutputValueClass(Text.class);

        job.addCacheFile(new URI("output-2/part-r-00000"));

        FileInputFormat.setInputPaths(job,new Path("output-1"));
        FileOutputFormat.setOutputPath(job,new Path("output-3"));

        boolean flag = job.waitForCompletion(true);
        System.exit( flag ? 0 : 1);
    }
}
